/**
 *  * Bestpay.com.cn Inc.
 *  * Copyright (c) 2011-2016 All Rights Reserved.
 *  
 */
package Test;/**
 * Created by feng on 2016/9/14.
 */

import com.google.common.util.concurrent.MoreExecutors;

import java.util.concurrent.*;

/**
  * 测试线程池中嵌套使用线程池会怎样
  * @author feng
  * @version Id: TestThreadPool.java, v 0.1 2016/9/14 17:14 feng Exp $$
  */
public class TestThreadPool {

    public  ExecutorService executorService;
    public  ExecutorService executor;

 public void runTest()
 {


     int threadSize = Runtime.getRuntime().availableProcessors() * 2;
     executorService= MoreExecutors.listeningDecorator(MoreExecutors.getExitingExecutorService
             (new ThreadPoolExecutor(threadSize, threadSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>())));
     executor=new ThreadPoolExecutor(4,8,5000,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());
     final CountDownLatch latch = new CountDownLatch(2);
     for(int i=0;i<2;i++)
     executorService.submit(new Runnable() {

         @Override
         public void run() {
             try {

                 executor.execute(new Runnable() {
                     @Override
                     public void run() {
                         System.out.println(1);
                     }
                 });

             } finally {
                 latch.countDown();
             }
         }
     });

 }

}